//
//  YCVistorView.swift
//  weiBoSwift
//
//  Created by 刘胤辰 on 16/7/19.
//  Copyright © 2016年 it.com. All rights reserved.
//

import UIKit

class YCVistorView: UIView {
    
    var closure:(()->())?
    
    // MARK : -- 懒加载
    private lazy var centerImage:UIImageView = {
        
        let img=UIImageView(image: UIImage(named: "visitordiscover_feed_image_house"))
        
        return img
    }()
    

    private lazy var maskImgView:UIImageView = {
        
        let img=UIImageView(image: UIImage(named: "visitordiscover_feed_mask_smallicon"))
        
        return img
    }()
    
    private lazy var loopCircle:UIImageView = {
        
        let img=UIImageView(image: UIImage(named: "visitordiscover_feed_image_smallicon"))
        
        return img
    }()
    
    private lazy var messageLab:UILabel={
        
        let lab=UILabel(text: "关注一些人，回这里看看有什么惊喜关注一些人，回这里看看有什么惊喜", textColor: UIColor.grayColor(), font: 14)
        
        lab.numberOfLines = 0
        lab.textAlignment = .Center
        
        return lab
    }()
    
    // MARK : -- 因为swift是静态语言，在编译的时候找不到其它类的方法，所以要转为oc的
    @objc private lazy var registerBtn:UIButton={
        
        let btn=UIButton(title: "注册", titleColor: UIColor.darkGrayColor(), font: nil)
        
        //此处如果用image的话不会全部平铺
        //        btn.setImage(UIImage(named: "common_button_white_disable"), forState: UIControlState.Normal)
        btn.addTarget(self, action: "clickLoadOrRegister", forControlEvents: UIControlEvents.TouchUpInside)
        btn.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: UIControlState.Normal)
        
        return btn
    }()
    @objc private lazy var loadBtn:UIButton={
        
        let btn=UIButton(title: "登陆", titleColor: UIColor.darkGrayColor(), font:nil)
        
        btn.addTarget(self, action: "clickLoadOrRegister", forControlEvents: UIControlEvents.TouchUpInside)
        btn.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: UIControlState.Normal)
        
        return btn
    }()
    

    func clickLoadOrRegister(){
        
        closure?()
    }
    
    //MARK:外界调用来进行赋值的方法
    func setEarchVCData(title:String?,imageName:String?){
        
        if let ti=title,let img=imageName {
            
            messageLab.text=ti
            centerImage.image=UIImage(named: img)
            loopCircle.hidden=true
        }else{
            
        }
    }
    
    //点击方法
    func click(){
        
        
    }

    //初始化方法
    override init(frame: CGRect) {
        
        super.init(frame: frame)
        backgroundColor = RGB(237, green: 237, blue: 237, alph: 1.0)
        
        //添加
        addSubview(loopCircle)
        addSubview(maskImgView)
        addSubview(centerImage)
        addSubview(messageLab)
        addSubview(registerBtn)
        addSubview(loadBtn)
        
        //设置约束
        centerImage.snp_makeConstraints { (make) -> Void in
            
            make.centerX.equalTo(self).offset(0)
            make.centerY.equalTo(self).offset(0)
        }
        loopCircle.snp_makeConstraints { (make) -> Void in
            
            make.centerX.equalTo(self).offset(0)
            make.centerY.equalTo(self).offset(0)
        }
        maskImgView.snp_makeConstraints { (make) -> Void in
            
            make.centerX.equalTo(self).offset(0)
            make.centerY.equalTo(self).offset(10)
        }
        messageLab.snp_makeConstraints { (make) -> Void in
            
            make.centerX.equalTo(self).offset(0)
            make.centerY.equalTo(maskImgView.snp_bottom).offset(-10)
            make.size.equalTo(CGSizeMake(230, 34))
        }
        registerBtn.snp_makeConstraints { (make) -> Void in
            
            make.left.equalTo(messageLab).offset(0)
            make.size.equalTo(CGSizeMake(100, 36))
            make.top.equalTo(messageLab.snp_bottom).offset(20)
        }
        loadBtn.snp_makeConstraints { (make) -> Void in
            
            make.right.equalTo(messageLab).offset(0)
            make.size.equalTo(CGSizeMake(100, 36))
            make.top.equalTo(messageLab.snp_bottom).offset(20)
        }
        makeLoopCircleRunning()

    }
    
    //MARK:设置图片转动
    func makeLoopCircleRunning(){
        
        let anim=CABasicAnimation(keyPath: "transform.rotation")
        anim.toValue=M_PI * 2
        anim.duration=10
        anim.repeatCount=MAXFLOAT
        anim.removedOnCompletion=false
        
        loopCircle.layer.addAnimation(anim, forKey: nil)
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    

}
